package com.miaoxie.forum.module.monitor.server.services.impl;

import com.miaoxie.forum.module.monitor.shared.util.SeleniumUtil;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

/**
 * Created by miaoxie on 2017/4/7.
 */

public class MBIFush {
    WebDriver webDriver;
    public void fush(){
        webDriver = SeleniumUtil.requestUrl();
//        WebElement userCode = webDriver.findElement(By.name("userCode"));
//        userCode.sendKeys("311198");
//        WebElement password = webDriver.findElement(By.name("password"));
//        password.sendKeys("admin311198");
//        WebElement submit = webDriver.findElement(By.xpath("/html/body/form/input[3]"));
//        submit.click();
        login();


    }
    private void login(){
        WebElement userCode = webDriver.findElement(By.name("userCode"));
        userCode.sendKeys("311198");
        WebElement password = webDriver.findElement(By.name("password"));
        password.sendKeys("admin311198");
        WebElement submit = webDriver.findElement(By.xpath("/html/body/form/input[3]"));
        submit.click();
        WebElement dashBord = webDriver.findElement(By.xpath("/html/body/div/div/div[1]/ul/li[1]"));
        dashBord.click();
        String a  = webDriver.getCurrentUrl();
        if(a.contains("login")){
            login();
        }
        try {
            WebElement button = webDriver.findElement(By.xpath("/html/body/div/div/div[2]/div[3]/table/tbody/tr[1]/td[3]/button"));
            button.click();
            WebElement loginForm = webDriver.findElement(By.id("layui-layer-iframe1"));
            WebDriver wb = webDriver.switchTo().frame(loginForm);
            WebElement starTime = wb.findElement(By.xpath("/html/body/div[1]/div/div[3]/div/input"));
            WebElement endTime = wb.findElement(By.xpath("/html/body/div[1]/div/div[4]/div/input"));
            starTime.sendKeys("2017-04-07 11:10");
            endTime.sendKeys("2017-04-07 11:15");
        }catch (Exception ex){
            login();
        }

    }

}
